
//格式定义
let userG = (/^[A-z]\w{3,15}$/);
let pwG = (/^[A-z0-9]{4,16}$/);
let emailG = (/^[1-9a-zA-Z_]\w*@[a-zA-Z0-9]+(\.[a-zA-Z]{2,})+$/);

//用户名验证
function checkusername(){
    let username=document.getElementById("userName");
    if(username.value==""){
        document.getElementById("userNameMessage").className="errorMessage";
        document.getElementById("userNameMessage").innerHTML="不能为空";
        document.getElementById("userNameImage").className="errorImage";
    }else if(userG.test(username.value)==false){
        document.getElementById("userNameMessage").className="errorMessage";
        document.getElementById("userNameMessage").innerHTML="输入格式不正确";
        document.getElementById("userNameImage").className="errorImage";
    }else{
        document.getElementById("userNameMessage").className="successMessage";
        document.getElementById("userNameMessage").innerHTML="输入格式正确";
        document.getElementById("userNameImage").className="successImage";
    }
}

//昵称验证
function checknickname(){
    let nickname=document.getElementById("nickName");
    if(nickname.value==""){
        document.getElementById("nickNameMessage").className="errorMessage";
        document.getElementById("nickNameMessage").innerHTML="不能为空";
        document.getElementById("nickNameImage").className="errorImage";
    }else{
        document.getElementById("nickNameMessage").className="successMessage";
        document.getElementById("nickNameMessage").innerHTML="输入正确";
        document.getElementById("nickNameImage").className="successImage";
    }
}

//密码验证
function checkpassword(){
    let password=document.getElementById("password");
    if(password.value==""){
        document.getElementById("passwordMessage").className="errorMessage";
        document.getElementById("passwordMessage").innerHTML="不能为空";
        document.getElementById("passwordImage").className="errorImage";
    }else if(pwG.test(password.value)==false){
        document.getElementById("passwordMessage").className="errorMessage";
        document.getElementById("passwordMessage").innerHTML="输入格式不正确";
        document.getElementById("passwordImage").className="errorImage";
    }else{
        document.getElementById("passwordMessage").className="successMessage";
        document.getElementById("passwordMessage").innerHTML="输入格式正确";
        document.getElementById("passwordImage").className="successImage";
    }
}

//重复密码验证
function checkrepassword(){
    let password=document.getElementById("password");
    let repassword=document.getElementById("rePassword");
    if(repassword.value==""){
        document.getElementById("rePasswordMessage").className="errorMessage";
        document.getElementById("rePasswordMessage").innerHTML="不能为空";
        document.getElementById("rePasswordImage").className="errorImage";
    }else if(repassword.value!=password.value){
        document.getElementById("rePasswordMessage").className="errorMessage";
        document.getElementById("rePasswordMessage").innerHTML="输入密码不一致";
        document.getElementById("rePasswordImage").className="errorImage";
    }else{
        document.getElementById("rePasswordMessage").className="successMessage";
        document.getElementById("rePasswordMessage").innerHTML="输入正确";
        document.getElementById("rePasswordImage").className="successImage";
    }
}



//邮箱验证
function checkemail(){
    let email=document.getElementById("email");
    if(email.value==""){
        document.getElementById("emailMessage").className="errorMessage";
        document.getElementById("emailMessage").innerHTML="不能为空";
        document.getElementById("emailImage").className="errorImage";
    }else if(emailG.test(email.value)==false){
        document.getElementById("emailMessage").className="errorMessage";
        document.getElementById("emailMessage").innerHTML="输入格式不正确";
        document.getElementById("emailImage").className="errorImage";
    }else{
        document.getElementById("emailMessage").className="successMessage";
        document.getElementById("emailMessage").innerHTML="输入格式正确";
        document.getElementById("emailImage").className="successImage";
    }
}